import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  token  : sessionStorage.getItem('ZHJF'),
  userMsg: JSON.parse(sessionStorage.getItem('userMsg')),

  menuList: [],

  componentURl    : '',
  dictionaryPrize : null,
  groupData       : {},
  fieldData       : {},
  componentHistory: [],

  onlineApply: {
    policyList: []
  },
  policysObj:'',//审核对象
  scrollTop:'',//我的审核实时高度
}

const mutations = {
  isLogin(state, _userMsg) {
    state.token   = sessionStorage.getItem('ZHJF')
    state.userMsg = _userMsg
  },
  setMenuList(state, menulist) {
    state.menuList = menulist
  },

  setDictionaryPrize(state, prize) {
    state.dictionaryPrize = prize;
  },
  setComponentURl(state, res) {
    state.componentURl = res
  },
  changeGroupData(state, res) {
    state.groupData = res
  },
  changeFieldData(state, res) {
    state.fieldData = res
  },
  deleteComponenthistory(state) {
    state.componentHistory.pop()
  },
  setComponentHistory(state, num) {
    state.componentHistory = state.componentHistory.slice(0, num)
  },
  resetComponentHistory(state, res) {
    state.componentHistory = []
    state.componentHistory.push(res)
  },
  addComponentHistory(state, res) {
    state.componentHistory.push(res)
  },

  setOnlineApply(state, obj) {
    state.onlineApply[obj.obj] = obj.res
  },
  //审核对象
  setPolicysObj(state,policyIdAll){
    state.policysObj = policyIdAll
  },
  //我的审核实时高度
  setScrollTop(state,scrollTop){
    state.scrollTop = scrollTop
  },
}
const getters   = {
  getGroupData       : state => state.groupData,
  getUserMsgData     : state => state.userMsg,
  getComponentHistory: state => state.componentHistory
}

export default new Vuex.Store({
  state,
  mutations,
  getters
})
